package com.atmilan.quartz.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atmilan.quartz.mapper.ProductSkuSupplierMapper;
import com.atmilan.quartz.model.entity.buyer.ProductSkuSupplier;
import com.atmilan.quartz.model.entity.buyer.ProductSkuSupplierExample;
import com.atmilan.quartz.service.IProductSkuSupplierService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

@Service
public class ProductSkuSupplierServiceImpl extends ServiceImpl<ProductSkuSupplierMapper, ProductSkuSupplier> implements IProductSkuSupplierService {
    @Autowired
    ProductSkuSupplierMapper productSkuSupplierMapper;

    @Override
    public List<ProductSkuSupplier> getBySkuIdAndSupplierIdAndOnSaleStatusAndStockGreater0(Long skuId, Long supplierId, Integer onSaleStatus, List<ProductSkuSupplier> productSkuSuppliers) {
        List<ProductSkuSupplier> resList = new ArrayList<>();
        for (ProductSkuSupplier productSkuSupplier : productSkuSuppliers) {
            if (productSkuSupplier.getSkuId().equals(skuId) && productSkuSupplier.getSupplierId().equals(supplierId) && productSkuSupplier.getOnSaleStatus().equals(onSaleStatus)) {
                resList.add(productSkuSupplier);
            }

        }

        return resList;
    }

    @Override
    public List<ProductSkuSupplier> getBySkuIdAndSupplierIdAndOnSaleStatusAndStockGreater0(Long skuId, Long supplierId, Integer onSaleStatus) {
        ProductSkuSupplierExample productSkuSupplierExample = new ProductSkuSupplierExample();
        productSkuSupplierExample.createCriteria().andSkuIdEqualTo(skuId).andSupplierIdEqualTo(supplierId).andOnSaleStatusEqualTo(onSaleStatus).andStockGreaterThan(0);
        return productSkuSupplierMapper.selectByExample(productSkuSupplierExample);
    }
}
